const request = (options) => {
  return new Promise((resolve, reject) => {
    // wx.showLoading({
    // 	title: '加载中...',
    // 	mask: true
    // })	
    wx.request({
      url: "https://www.congdianxia.com/api" + options.url,
      // url: "http://zphqcq.natappfree.cc" + options.url,
      // url: "http://192.168.0.44:9500" + options.url,
      // url: "http://192.168.0.45:9500" + options.url,

      method: options.method || "POST",
      data: options.data,
      header: options.header || {
        "Content-Type": "application/json" || options.method == 'GET' ? "application/json" : "application/x-www-form-urlencoded;charset=utf-8",
        "authorization": wx.getStorageSync('extraData').authorization || 'eyJhbGciOiJIUzUxMiJ9.eyJhY2NvdW50SWQiOjExMywiYWdlbnRJZCI6MSwicm9sZSI6MSwicGhvbmUiOjEzMTQwMjk4NjExLCJvcGVuaWQiOiJvdElJYTVFakZvZnFpUVVpcHQ4eDB3cjlBaF9nIiwiYWdlbnROYW1lIjoi5byg5pm65LquIiwib3BlcmF0aW9uX2F1dGgiOiJlbmFibGUiLCJleHAiOjE3NDQyNzA0MjJ9.nnXYL16Pqh5f4oZHc_OTMUAuDJxmBDa0ikEJ0PBq1cN_duKXvQa1WGAR-gehBek0Ag3r1fhK7SE_55KbnAXSaw',
        "appid": "wx689a1e9fff0eca30",

      },
      success: (res) => {
        // wx.showToast({	
        // 			icon: 'none',
        // 			title: res.data.message || '',
        // 			duration: 3000	
        // 		})
        resolve(res)

        if (res.data.code == 401 || res.data.code == 1016) {

          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 3000,
            mask: true,
          })

          setTimeout(() => {
            wx.reLaunch({
              url: '/pages/login/login',
            })
          }, 2500);
        }
      },
      fail: (err) => {
        wx.hideLoading()
        wx.showToast({
          icon: 'none',
          title: '网络异常',
          duration: 3000
        })
        reject(err)
        wx.vibrateLong()
      }
    })
  }).catch(err => {

  })
}
export default request